#include "Goal.h"

Goal::Goal(D3DXVECTOR2 pos) :GameObject(pos,EGoal)
{
	mark = new CSprite(ResourceManager::GetIns()->GetTexture(Mark_ID),1,1,1,0,0);
	collum = new CSprite(ResourceManager::GetIns()->GetTexture(Collum_ID),1,1,1,0,0);
	ladder = new CSprite(ResourceManager::GetIns()->GetTexture(Ladder_ID),1,1,1,0,0);
	m_pSprite = ladder;
	isMaxH = false;
	collumPos = pos + D3DXVECTOR2(300,120);
	ladderPos = pos + D3DXVECTOR2(300,0);
	m_velocity = D3DXVECTOR2(0,LADDERSPEED);
	maxH = ladderPos.y + 270;
	minH = ladderPos.y;
}

Goal::~Goal()
{
	GameObject::~GameObject();
}

void Goal::Update(float dt)
{
	ladderPos += m_velocity*dt*60;
	if(ladderPos.y >= maxH)
	{
		isMaxH = true;
	}
	if(ladderPos.y <=minH)
	{
		isMaxH = false;
	}
	if(isMaxH==false)
		m_velocity.y = LADDERSPEED;
	else
		m_velocity.y = -LADDERSPEED;
}

void Goal::Draw()
{
	mark->Draw(m_position,SpriteEffect::None,0,1);
	collum->Draw(collumPos,SpriteEffect::None,0,1);
	m_pSprite->Draw(ladderPos,SpriteEffect::None,0,1);
}

CRect Goal::GetBound()
{
	CRect rectOut = ladder->GetBound();
	rectOut._x = ladderPos.x- rectOut._width/2;
	rectOut._y = ladderPos.y- rectOut._height/2;
	return rectOut;
}

Box Goal::GetBox()
{
	Box b(ladderPos.x, ladderPos.y,ladder->GetBound()._width,ladder->GetBound()._height,m_velocity.x,m_velocity.y);
	return b;
}